<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"
	xmlns:pe="http://primefaces.org/ui/extensions">

	<ui:composition template="/templates/masterLayout.xhtml">
		<ui:define name="content">
			<h:form id="dinhMucListFormId">
				<p:messages autoUpdate="true" />
				<p:dataTable id="dinhMucDataTableId" value="#{dinhMucView.dataModel}" resizableColumns="true"
					selection="#{dinhMucView.selectedEntities}" paginator="true" var="entity" rows="10"
					paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
					lazy="true" paginatorPosition="bottom">
					<f:facet name="header">
						<p:commandButton value="Lập định mức ngay" action="#{dinhMucView.lapDinhMucNgay}" update="@form"></p:commandButton>
					</f:facet>
					<p:column headerText="MSSP">
						<h:outputText value="#{entity.sanPham.code}" />
					</p:column>

					<p:column headerText="Tên SP" sortBy="#{entity.sanPham.name}">
						<h:outputText value="#{entity.sanPham.name}" />
					</p:column>
					<p:column headerText="Định mức bán" sortBy="#{entity.dinhMucBan}">
						<p:inplace editor="true">
							<p:ajax event="save" listener="#{dinhMucView.updateDinhMuc(entity)}" />
							<p:ajax event="cancel" listener="#{dinhMucView.reset}" update="@this" />
							<p:inputText id="dinhMucBanId" value="#{entity.dinhMucBan}" onkeypress="onKeypressInplace(event, this)" />
							<pe:keyFilter for="dinhMucBanId" mask="pint" />
						</p:inplace>

					</p:column>
					<p:column headerText="Còn lại">
						<p:inplace editor="true">
							<p:ajax event="save" listener="#{dinhMucView.updateDinhMuc(entity)}" />
							<p:ajax event="cancel" listener="#{dinhMucView.reset}" update="@this" />
							<p:inputText id="dinhMucConLaiId" value="#{entity.conLai}" onkeypress="onKeypressInplace(event, this)" />
							<pe:keyFilter for="dinhMucConLaiId" mask="pint" />
						</p:inplace>
					</p:column>

					<p:column width="30">
						<p:commandButton icon="ui-icon-refresh" value="#{rowIndex}" action="#{dinhMucView.canBangDinhMuc(entity)}"
							update="@form"></p:commandButton>
					</p:column>
				</p:dataTable>

				<!-- When press the enter key, the button "Lập định mức ngay" will be called as default, 
				even we return false in the function onKeypressInplace. 
				To avoid this, I create the pretend default button and set it as default, that means it do nothing -->
				<p:commandButton id="pretendButton" style="display:none" type="button" />
				<p:defaultCommand target="pretendButton"></p:defaultCommand>
			</h:form>
		</ui:define>
	</ui:composition>


</ui:composition>